var login = {
		init: function(){
			//提交
			$(".weui-btn.weui-btn_primary").click(function(){
				$(".weui-cell").removeClass("weui-cell_warn");
				var email = $("#username").val();
				var password = $("#password").val();
				var imageCode = $("#imageCode").val();
				var check = true;
				if(""==email){
					$("#username").parents(".weui-cell").addClass("weui-cell_warn");
					check = false;
				}
				if(""==password){
					$("#password").parents(".weui-cell").addClass("weui-cell_warn");
					check = false;
				}
				if(""==$(".weui-cell_vcode").attr("style")){
					if(""==imageCode){
						$(".weui-cell_vcode").addClass("weui-cell_warn");
						check = false;
					}
				}
				if(!check){
					return false;
				}
				$.post("/loginSubmit",{
					email:email,
					password:password,
					imageCode:imageCode
				},function(data){
					if(data.code=="200"){
						//登录成功跳转
						window.location.href="/mobile/home";
					}else{
						$("#error_dialog .weui-dialog__bd").text(data.msg);
						$(".err-msg").text(data.msg);
						$("#error_dialog").show();
						if(data.code=="1006"){
							$(".weui-cell_vcode").show();
						}
					}
				},"json");
				
				
			});
				
			$(".weui-vcode-img").click(function(){
				var $that = $(this);
				$that.attr("src","/valicode?t="+new Date().getTime());
			});
			
			$("#username").blur(function(){
				$.post("/countUserError",{
					email:$("#username").val()
				},function(data){
					if(parseInt(data)>0){
						$(".weui-cell_vcode").show();
					}
				})
			});
			//关闭错误窗口
			$(".weui-dialog__btn.weui-dialog__btn_primary").click(function(){
				$(this).parents(".js_dialog").hide();
			});
		}
};
login.init();